from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, DATE, NUMBER

# 创建对象的基类
Base = declarative_base()


# 生成结果历史类
class BusinessInfo(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_DW_GSXX_CETC'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)  # 编号
    GSMC = Column(VARCHAR2(128))  # 公司名称
    FDDBR = Column(VARCHAR2(36))  # 法定代表人
    ZZZB = Column(VARCHAR2(64))  # 注册子泵
    YX = Column(VARCHAR2(64))  # 邮箱
    CLRQ = Column(DATE)  # 成立日期
    TYSHXYDM = Column(VARCHAR2(64))  # 统一社会信用代码
    LXDH = Column(VARCHAR2(36))  # 联系电话
    ZCDZ = Column(VARCHAR2(128))  # 注册地址
    JYFW = Column(VARCHAR2(512))  # 经营范围
    QYGM = Column(VARCHAR2(32))  # 企业规模
    SSSF = Column(VARCHAR2(32))  # 所属省份
    GBHYML = Column(VARCHAR2(64))  # 国标行业门类
    GBHYDL = Column(VARCHAR2(64))
    IS_CYDW = Column(NUMBER)
    IS_XWQY = Column(NUMBER)
    IS_MYGS = Column(NUMBER)
    DJZT = Column(VARCHAR2(36))
    HZRQ = Column(DATE)
    GS = Column(VARCHAR2(64))
    CJRQ = Column(DATE)
    BH = Column(VARCHAR2(64))

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID=int(data.get('ID')) if data.get('ID') is not None else 0,
            GSMC=data.get('GSMC'),
            FDDBR=data.get('FDDBR'),
            ZZZB=data.get('ZZZB'),
            YX=data.get('YX'),
            CLRQ=data.get('CLRQ'),
            TYSHXYDM=data.get('TYSHXYDM'),
            LXDH=data.get('LXDH'),
            ZCDZ=data.get('ZCDZ'),
            JYFW=data.get('JYFW'),
            QYGM=data.get('QYGM'),
            SSSF=data.get('SSSF'),
            GBHYML=data.get('GBHYML'),
            GBHYDL=data.get('GBHYDL'),
            IS_CYDW=data.get('IS_CYDW'),
            IS_XWQY=data.get('IS_XWQY'),
            IS_MYGS=data.get('IS_MYGS'),
            DJZT=data.get('DJZT'),
            HZRQ=data.get('HZRQ'),
            GS=data.get('GS'),
            CJRQ=data.get('CJRQ'),
            BH=data.get('BH')
        )

    def to_dict(self):
        return {
            'ID': self.ID,
            'GSMC': self.GSMC,
            'FDDBR': self.FDDBR,
            'ZZZB': self.ZZZB,
            'YX': self.YX,
            'CLRQ': self.CLRQ,
            'TYSHXYDM': self.TYSHXYDM,
            'LXDH': self.LXDH,
            'ZCDZ': self.ZCDZ,
            'JYFW': self.JYFW,
            'QYGM': self.QYGM,
            'SSSF': self.SSSF,
            'GBHYML': self.GBHYML,
            'GBHYDL': self.GBHYDL,
            'IS_CYDW': self.IS_CYDW,
            'IS_XWQY': self.IS_XWQY,
            'IS_MYGS': self.IS_MYGS,
            'DJZT': self.DJZT,
            'HZRQ': self.HZRQ,
            'GS': self.GS,
            'CJRQ': self.CJRQ,
            'BH': self.BH
        }
